//
//  FFReceiverMessageHandler.m
//  FFWebChat
//
//  Created by IT.Bear on 2017/10/25.
//  Copyright © 2017年 FashionFenke. All rights reserved.
//

#import "FFReceiverMessageHandler.h"
#import <AudioToolbox/AudioToolbox.h>
#import "AppDelegate.h"

static FFReceiverMessageHandler *receiverHandler;

@implementation FFReceiverMessageHandler


+ (FFReceiverMessageHandler *)sharedInstance {
    static dispatch_once_t oncetoken;
    dispatch_once(&oncetoken,^{
        if (!receiverHandler) {
            receiverHandler = [[self alloc] init];
        }
    });
    return receiverHandler;
}

- (void)handlerReceiver{
    UIApplicationState state = [[UIApplication sharedApplication] applicationState];
    switch (state) {
        case UIApplicationStateActive:
        {
            [self playNewMessageSound];
            [self playVibration];
        }
            break;
        case UIApplicationStateInactive:
        {
            [self playNewMessageSound];
            [self playVibration];
        }
        case UIApplicationStateBackground:
        {
            [self playNewMessageSound];
            [self playVibration];
        }
            break;
        default:
            break;
    }
    
}

// 播放接收到新消息时的声音
- (void)playNewMessageSound
{
    // 创建系统声音
    SystemSoundID soundID = (UInt32)1007;
    AudioServicesPlaySystemSound(soundID);
}

// 震动
- (void)playVibration
{
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
@end
